import 'package:agora_rtc_engine/rtc_engine.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_author/utils/user_util.dart';

import '../model/channel.dart';
import '../utils/common_util/num_util.dart';

/// [normal]：#333333
/// [gray]：#666666
/// [lightGray]:#999999
class ColorConf {
  static const Color transparent = Color(0x00FFFFFF);

  static const Color normal = Color(0xFF333333);

  static const Color darkGray = Color(0xFFF5F5F5);

  static const Color gray = Color(0xFF666666);

  static const Color lightGray = Color(0xFF999999);

  static const Color shallowGray = Color(0xFFF8F8F8);

  static const Color highlightGray = Color(0xFFCCCCCC);

  static const Color white = Color(0xFFFFFFFF);

  static const Color darkWhite = Color(0xFFEEEEEE);

  static const Color black = Color(0xFF000000);

  static const Color blue = Color(0xFF037AFF);

  static const Color red = Color(0xFFE02020);

  static const Color red2 = Color(0xFFF04529);

  static const Color lightRed = Color(0x1AE02020);

  static const Color yellow = Color(0xFFFEBA07);

  static const Color yellow2 = Color(0xFFF8D86A);

  static const Color lightYellow = Color(0x33F8D86A);

  static const Color orange = Color(0xFFFF8F00);

  static const Color gold = Color(0xFFCCAD69);

  static const Color green = Color(0xFF44A949);

  static const Color cyan = Color(0xFFB2CF87);

  static const Color lightGreen = Color(0xFFF2FBF2);

  static const Color brown = Color(0xFF8B572A);

  static LinearGradient get orangeGradient => LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFFFEBA07), Color(0xFFF8D86A)],
      );

  static LinearGradient get redGradient => LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: [Color(0xFFF04529), Color(0xFFFF8774)],
      );

  static LinearGradient get orangeGradient2 => LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: [Color(0xFFFF8F00), Color(0xFFFEBA07)],
      );
}

/// 按钮默认配置
class ButtonConf {
  static BorderRadius get defaultRadius => BorderRadius.circular(100.0);

  static double get defaultHeight => 46.0;
}

/// 输入框默认配置
class TextFieldConf {
  static double get defaultFontSize => 16;
}

class Version {
  static const int major = 1;
  static const int mirror = 1;
  static const int patch = 1;

  static String get fullString => 'V${major}.${mirror}.${patch}';
}

class StreamConf {
  static String appid = 'a43f4f160d88455cb1a15454b7520a06';

  static bool get playing => uid != -1;

  static bool isJoinRongCould = true;

  static String PushBaseUrlDefault = "rtmps://examplepush.agoramdn.com/live/";

  static String PullBaseUrlDefault = "https://examplepull.agoramdn.com/live/";

  static String PushBaseUrl = "rtmps://agora-push.huiliu.net/live/";

  static String PullBaseUrl = "https://agora-play.huiliu.net/live/";

  //推流域名
  static String rtmpPushUrl = PushBaseUrl + channelKey;

  //播放流域名----ios 不能使用flv格式播放 只能使用m3u8
  static String rtmpPullUrl = "$PullBaseUrl$channelKey.m3u8";

  //直播间channelKey
  static String channelKey = "73ca5530f233ba21f65d091b5e66fe9b";
  static int uid = -1; //直播中的主播id
  static int liveId = -1; //直播间id
  static String token = ""; //直播token
  static String cover = ""; //直播间封面
  // static StreamStatus status = StreamStatus.NoLiveNotice;//当前直播间状态
  static int barrageMaxLength = 6; //弹幕最多显示条数
  static double barrageLineHeight = 32.w; //单个弹幕高度
  static double get barrageMaxHeight =>
      (barrageMaxLength * barrageLineHeight) + 40.w;
  static double barrageMinHeight = 100;
  static bool isShowVideo = true; //是否显示浮窗 默认显示 只有直播间关闭按钮点击不显示
  static ChannelModel? channelModel = null;
  static bool isConnect = false; // 是否连麦中

  static late RtcEngine engine;

  //todo:Hidden:视频尺寸等比缩放。优先保证视窗被填满。因视频尺寸与显示视窗尺寸不一致而多出的视频将被截掉。
  //todo:Fit:视频尺寸等比缩放。优先保证视频内容全部显示。因视频尺寸与显示视窗尺寸不一致造成的视窗未被填满的区域填充黑色。
  //todo:FILL:视频尺寸进行缩放和拉伸以充满显示视窗
  static VideoRenderMode renderMode = VideoRenderMode.Hidden;

  //Enabled
  // 1: 启用镜像模式。
  // Disabled
  // 2: 关闭镜像模式。
  static VideoMirrorMode videoMirrorMode = VideoMirrorMode.Disabled;

  static VideoRenderMode AudienceVideoMirrorMode = VideoRenderMode.Fit;

  static String chatRoomEntry = "chatRoomEntryCount"; //直播间点击总数

  static List barrages = [];

  static int viewUserCount = 0;

  static VideoRemoteState remoteState = VideoRemoteState.Stopped; //当前视频状态

  static bool joined = false; //是否在直播间

  static List<String> live_actions = [
    'join_studio',
    'close_studio',
    'ban_user',
    'unban_user',
  ];
  static int currentGoodSeconds = 0;

  //CDN推流主播画面
  static List<TranscodingUser> users = [
    TranscodingUser(
      UserUtil.getUserId(Get.context!),
      width: MyVideoDimensions.width,
      height: MyVideoDimensions.height,
      x: 0,
      y: 0,
    ),
  ];
}

//直播观看数量方法

int thousand = 100000;

getLiveHeat(person, {heat: 0}) {
  String result = "";
  if (heat == 0) {
    double count = NumUtil.multiply(
        person, double.tryParse(StreamConf.channelModel?.factor ?? "0") ?? 0);
    if (count >= thousand) {
      double p = NumUtil.divide(count, 10000);
      result = "${p.toStringAsFixed(2)}w";
    } else {
      result = count.toInt().toString();
    }
  } else {
    double count = NumUtil.multiply(person, heat);
    if (count >= thousand) {
      double p = NumUtil.divide(count, 10000);
      result = "${p.toStringAsFixed(2)}w";
    } else {
      result = count.toInt().toString();
    }
  }

  return result;
}

//直播画质
class Bitrate {
  static const int b_1920_x_1080_60 = 6500;
  static const int b_1920_x_1080_30 = 6300;
  static const int b_1280_x_720_30 = 3420;
}

//视频尺寸
class MyVideoDimensions {
  static get width => 719;

  static get height => 1279;
  static double aspectRatio = width / height;
}

//视频播放格式
class VideoFormat {
  static String m3u8 = ".m3u8";
}

class UmengVerifySdkConfig {
  static String androidInfo =
      'HXlfMGSoYCmXhSdvm726QITngALju/r90aBoYFAdG9KUxf0J9qeV/kw+35cp+2gJrNlQOssLvsVL2uNfe3eVjsWfMzJENPyTwlYUBQrxHCojGfMlmwci19WpbD4A01TfkUm/l0it0IUovM0WCwWF8LsumQc6w0C+dg+5Dt97q8T25ctiupPI3yqltSN1P2cCiZrkGrYWE88pdSifvBH1rB1lMgQmzF8TOBThBavD+ClyAp5WA+ROizj7lVgZnQNSdmkRFMc+HSgJg9gXp8oFtK49eX3jifRxpFCpImVstWbV4y0xurh1ZA==';
  static String iosInfo =
      'IVbJgFY8/Wi5RXBXTcPprCLnxi/VGq1W+xEfrH005O7Z7OJp1zU/W1MAG3OqYMuDCVf1IqS6+ovmIdFzcxOLK1QvlpkSAfuk/t8oG10unVwWvf9rr3DtfvZlb0wLb6dusewxjIvZV0UKKJXe6D03WKAeOQuMowEuISlKhbH9x0Oci6qBjnnyN3xGwhhw8Bx0iJoxCBFfhp9hv6UjX34rBMdwd5mrMEqvP2zP1k4P0XHg2d0d5oHzRxYRnizqni1wLujiRoRk93M=';
}
